package com.funcourse.demo.wechat.client.web;

import com.funcourse.demo.wechat.client.web.io.resp.QueryUserInfoResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class UserInfoGetter {

  static final String REQUEST_ADDRESS = "https://api.weixin.qq.com/sns/userinfo?access_token={ACCESS_TOKEN}&openid={OPENID}";
  @Autowired
  RestTemplate restTemplate;

  public QueryUserInfoResponse getUserInfo(String accessToken, String openId) {
    return restTemplate.getForObject(REQUEST_ADDRESS, QueryUserInfoResponse.class,
        accessToken, openId);
  }

}
